package org.javabrains.koushik.hibernate;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.javabrains.koushik.dto.Address;
import org.javabrains.koushik.dto.Student;

public class TestStudent {

	
	
	public static void main(String args[]){
		
		SessionFactory sessionfactory = new Configuration().configure().buildSessionFactory();
		Session session = sessionfactory.openSession();
		session.beginTransaction();
		
		
		
		Student student = new Student();
		
		student.setAge(25);
		student.setName("Viva");
		student.setDescription("dfdfdfdfdf");
		student.setDob(new Date());
		
		Address address = new Address();
		
		address.setCity("cochin");
		address.setPincode("585822");
		address.setState("kerala");
		address.setStreet("S N RD");
		
		
		student.setAddress(address);
		
		session.save(student);
		session.getTransaction().commit();
		
		
		session.beginTransaction();
		Student stud = (Student)session.get(Student.class, 1);
		
		System.out.println("Name : " + stud.getName());
		
		
		
		
		session.getSessionFactory().close();
		
		
		
	} //psvm
	
	
}
